home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
WASTE 1.2
/
WASTE Demo ƒ
/
WEDemoAbout.c
< prev
next >
Wrap
Text File
|
1996-05-19
|
3KB
|
138 lines
/*
WASTE Demo Project:
About Boxes
Copyright © 1993-1996 Marco Piovanelli
All Rights Reserved
C port by John C. Daub
*/
#ifndef __WEDEMOAPP__
#include "WEDemoIntf.h"
#endif
// some local stuff
enum {
kItemTextPane = 3
};
OSErr WETextBox( short textResID, const Rect *bounds, WEAlignment alignment )
{
WEReference we = nil;
Handle hText = nil;
Handle hStyles = nil;
LongRect longBounds;
SInt8 saveTextState, saveStylesState;
OSErr err;
// create a new WE instance
WERectToLongRect( bounds, &longBounds );
if ( ( err = WENew( &longBounds, &longBounds, 0, &we ) ) != noErr )
goto cleanup;
// set the alignment style
WESetAlignment( alignment, we );
// load the styl resource and make it unpurgeable
hStyles = GetResource( kTypeStyles, textResID );
if ( ( err = ResError( ) ) != noErr )
goto cleanup;
saveStylesState = HGetState( hStyles );
HNoPurge( hStyles );
// load the text resource and lock it
hText = GetResource( kTypeText, textResID );
if ( ( err = ResError( ) ) != noErr )
goto cleanup;
saveTextState = HGetState( hText );
HLockHi( hText );
// insert the text
if ( ( err = WEInsert( *hText, GetHandleSize( hText ), (StScrpHandle) hStyles, nil, we ) ) != noErr )
goto cleanup;
// clear the result code
err = noErr;
cleanup:
if ( hText != nil )
{
HSetState( hText, saveTextState );
}
if ( hStyles != nil )
{
HSetState( hStyles, saveStylesState );
}
WEDispose( we ); // WEDispose is nil-safe
// return the result code
return err;
}
static pascal void DrawUserItem( DialogRef dialog, short item )
{
Rect r;
// draw the text, centered, in the item rect
GetDialogItemRect( dialog, item, &r );
WETextBox( GetWRefCon( GetDialogWindow( dialog ) ), &r, weCenter );
}
void DoAboutBox( short dialogID )
{
DialogRef aboutBox;
short itemHit;
#ifdef __cplusplus
static UserItemUPP sBoxPainterUPP = NewUserItemProc( DrawUserItem );
#else
static UserItemUPP sBoxPainterUPP = nil;
if ( sBoxPainterUPP == nil )
{
sBoxPainterUPP = NewUserItemProc( DrawUserItem );
}
#endif
// get the about box
if ( ( aboutBox = GetNewDialog( dialogID, nil, (WindowRef) -1L ) ) == nil )
return;
// install a user item drawing procedure for the text pane
SetDialogItemProc( aboutBox, kItemTextPane, sBoxPainterUPP );
// store ID of TEXT/styl pair (= ID of dialog template) in dialog refCon
SetWRefCon( GetDialogWindow( aboutBox ), dialogID );
// put up the dialog
SetCursor( &qd.arrow );
ShowWindow( GetDialogWindow( aboutBox ) );
SetGrafPortOfDialog( aboutBox );
// wait for a click
ModalDialog( GetMyStandardDialogFilter( ), &itemHit );
// bring down the dialog
DisposeDialog( aboutBox );
}